package com.zsr.base64;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;

public class Base64Test {
    public static void main(String[] args) throws Exception {
        String s = "这是编码的主要内容";
        //创建一个Base64编码器
        BASE64Encoder base64Encoder=new BASE64Encoder();
        //执行Base64编码操作
        String encodeString = base64Encoder.encode(s.getBytes("UTF-8"));

        System.out.println(encodeString);

        //解码
        BASE64Decoder base64Decoder=new BASE64Decoder();
        byte[] bytes = base64Decoder.decodeBuffer(encodeString);

        String  result=new String(bytes,"UTF-8");
        System.out.println(result);
    }
}
